<template>
  <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
    <el-alert
      title="确定要执行备份操作吗"
      type="info"
      description="备份后，可以从【备份记录】查看所有备份版本"
      show-icon
    />
    <el-form-item label="备份名称" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="备注" prop="desc">
      <el-input v-model="ruleForm.desc" type="textarea" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm',ruleForm)">立即创建</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  props: {
    backupData: {},
    comment: {}
  },
  data() {
    return {
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '请填写备注', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName, formData) {
      var studentAllData = JSON.stringify(this.backupData)
      var columnComment = this.comment
      formData = JSON.stringify(formData)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('cancalDialog', false)
          this.$post('dataCenter/dataBackup', {
            formData, studentAllData, columnComment
          }).then((r) => {
            console.log(r)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
